const SysIconDao = appRequire(`dao/desktop/bk/SysIconSqliteDao.js`);
const uuid = require('uuid');
var dateFormat = require("dateformat");
const SqliteUtil = require('../../modules/SqliteUtil');
class SysIconService {
    constructor() {

    }
    static async save(icon) {
        if (icon.id === '' || icon.id === undefined) {
            icon.id = uuid.v1();
            icon.createTime = dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss");
            icon.updateTime = icon.createTime;
            await SysIconDao.saveOne(icon);
            return icon.id;
        } else {
            let dbObj = await SysIconDao.findById(icon.id);
            SqliteUtil.dbObjectToEntity(dbObj,icon);
            icon.updateTime = dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss");
            await SysIconDao.updateOne(icon);
        }
    }

    static async deleteOne(id) {
        return await SysIconDao.deleteById(id);
    }

    static async deleteMany(ids) {
        ids = JSON.parse(ids);
        return await SysIconDao.deleteMany(ids);
    }

    static async findOne(id) {
        return await SysIconDao.findOne(id);
    }

    static async findAll() {
        return await SysIconDao.findAll();
    }

    static async findByPage(page) {
        page.pageNum = parseInt(page.pageNum);
        page.pageSize = parseInt(page.pageSize);
        page.searchParams = JSON.parse(page.searchParams);
        return await SysIconDao.findByPage(page);
    }

}
module.exports = SysIconService;